<template>
    <div class="app-container">
        <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" @closed="$emit('close')">
            <x-form ref="xForm" v-model="formData" v-loading="loading" :config="formConfig" />
        </el-dialog>
    </div>
</template>
  
<script>
import { addOrUpdateSuggestion } from '@/api/suggestion'
import { getToken } from '@/utils/auth'

export default {
    props: {
        id: {
            type: String,
            default: null
        },
        formData2: {
            
        }
    },
    data() {
        return {
            dialogTitle: '回复区',
            dialogVisible: true,
            formDisabled: false,
            loading: 0,
            showBtn: true,
            formData: this.formData2,
            showNoSee: false
        }
    },
    computed: {
        formConfig() {
            const _this = this
            return {
                disabled: _this.formDisabled,
                inline: false,
                item: [
                    { xType: 'input', name: 'userName', label: '用户名', disabled: true },
                    { xType: 'input', name: 'content', label: '意见内容', disabled: true, type: 'textarea' },
                    { xType: 'input', name: 'reply', label: '回复', type: 'textarea' }
                ],
                operate: [
                    { text: '回复', show: _this.showBtn, click: _this.addOrUpdateSuggestion },
                    { text: '取消', show: _this.showBtn, click: () => { _this.dialogVisible = false } }
                ]
            }
        }
    },
    watch: {

    },
    methods: {
        addOrUpdateSuggestion() {
            this.$refs['xForm'].validate().then(() => {
                this.loading++;
                addOrUpdateSuggestion(this.formData, getToken()).then(res => {
                    console.log('addOrUpdateSuggestion' + res)
                    this.dialogVisible = false
                    this.$message.success(res.message)
                    this.$emit('refresh')
                }).catch(e => console.error(e)).finally(() => this.loading--)
            }).catch(e => console.error(e))
        }
    }
}
</script>